//
//  DNChangeLanguageVC.m
//  DanoneEA
//
//  Created by Senela on 16/12/26.
//  Copyright © 2016年 翔傲科技. All rights reserved.
//

#import "DNChangeLanguageVC.h"
#import "TTILanguageTool.h"

@interface DNChangeLanguageVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;
@end

@implementation DNChangeLanguageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    NAV_INIT(self,
             DNNSLocalizedString(@"BtnTitle_LanguageChange", @""),
             nil, nil, nil, nil);

    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    
    [self.tableView setDelegate:self];
    [self.tableView setDataSource:self];
    [self.view addSubview:self.tableView];
    
    [self.tableView registerClass :[UITableViewCell class] forCellReuseIdentifier:@"LanguageCell"];
    
    [self.tableView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
    self.tableView.tableFooterView = [[UIView alloc] init];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LanguageCell" forIndexPath:indexPath];
   if(!cell)
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:@"LanguageCell"];
    
    if(indexPath.row == 0)
    {
        cell.textLabel.text = DNNSLocalizedString(@"Language_English", @"");
    }
    else if(indexPath.row == 1)
    {
        cell.textLabel.text = DNNSLocalizedString(@"Language_Chinese", @"");
    }
    else if (indexPath.row == 2)
    {
        cell.textLabel.text = DNNSLocalizedString(@"Language_Malay", @"");
    }
    else if (indexPath.row == 3)
    {
        cell.textLabel.text = DNNSLocalizedString(@"Language_Thai", @"");
    }
    else if (indexPath.row == 4)
    {
        cell.textLabel.text = DNNSLocalizedString(@"Language_Turkish", @"");
    }
    else if (indexPath.row == 5)
    {
        cell.textLabel.text = DNNSLocalizedString(@"Language_Polish", @"");
    }
    else if (indexPath.row == 6)
    {
        cell.textLabel.text = DNNSLocalizedString(@"Language_German", @"");
    }
 
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        [[TTILanguageTool sharedInstance] setNewLanguage:English];
    }
    else if(indexPath.row == 1)
    {
        [[TTILanguageTool sharedInstance] setNewLanguage:Chinese];
    }
    else if (indexPath.row == 2)
    {
        [[TTILanguageTool sharedInstance] setNewLanguage:Malay];
    }
    else if (indexPath.row == 3)
    {
        [[TTILanguageTool sharedInstance] setNewLanguage:Thai];
    }
    else if (indexPath.row == 4)
    {
        [[TTILanguageTool sharedInstance] setNewLanguage:Turkish];
    }
    else if (indexPath.row == 5)
    {
        [[TTILanguageTool sharedInstance] setNewLanguage:Polish];
    }
    else if (indexPath.row == 6)
    {
        [[TTILanguageTool sharedInstance] setNewLanguage:German];
    }
    
     [self dismissViewControllerAnimated:YES completion:nil];
}


@end
